﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace MyCraft.Minecraft_2D.Blocs
{
    class Wood : Bloc
    {
        #region Attributs
        bool _isVertical;
        Texture2D _image0, _image90;
        #endregion

        #region Constructeur
        public Wood(Vector2 position, double timer, ContentManager content)
            : base(timer, 50)
        {
            _light = -6;
            _minLight = 0;
            _id = 3;
            _name = "Wood";
            _percent = 30;
            _color = Color.SaddleBrown;
            _image0 = (content != null) ? content.Load<Texture2D>(@"Blocs\Wood") : null;
            _image90 = (content != null) ? content.Load<Texture2D>(@"Blocs\Wood - 90") : null;

            SwitchOrientation(position);

            _actionBloc = delegate(Block b, Vector2 p, double t)
            {
                SwitchOrientation(p);
                return this;
            };
        }
        #endregion

        #region Proprietes
        #endregion

        #region Methodes
        private void SwitchOrientation(Vector2 position)
        {
            if (position.X <= 0.25f || position.X >= 0.75f)
                _isVertical = false;
            else
                _isVertical = true;

            if (_isVertical)
                _image = _image0;
            else
                _image = _image90;
        }

        public override TypeBloc OnNew(Block bloc)
        {
            TypeBloc down = bloc.Bottom;
            if (down == TypeBloc.Grass ||
                down == TypeBloc.Dirt ||
                down == TypeBloc.Wood)
            {
                if (down == TypeBloc.Grass)
                {
                    TypeBloc newbloc = BlocSet.GetSingleton()[TypeBloc.Dirt].OnNew(bloc);
                    if (newbloc != TypeBloc.None)
                        bloc.Bottom.Type = newbloc;
                }
                return TypeBloc.Wood;
            }
            return TypeBloc.None;
        }

        public override Bloc OnLife(double timer)
        {
            return base.OnLife(timer);
        }
        #endregion
    }
}
